package EjemplosEventosBasicos;

import java.awt.BorderLayout;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JFrame;
import javax.swing.JTextField;

public class EjemploFocusListener {
	
	public void montarVentana (){
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JTextField tf = new JTextField();
		
		tf.addFocusListener(new FocusListener(){

			public void focusGained(FocusEvent e) {
				System.out.println("Tf ha recuperado el foco de teclado");
				
			}

			public void focusLost(FocusEvent e) {
				System.out.println("Tf ha perdido el foco de teclado");
				
			}
			
		});
		
		JTextField tf2 = new JTextField();
		tf2.addFocusListener(new FocusAdapter(){
			public void focusGained(FocusEvent e) {
				System.out.println("Tf2 ha recuperado el foco de teclado");
				
			}
		});
		
		frame.add(tf, BorderLayout.NORTH);
		frame.add(tf2, BorderLayout.SOUTH);
		frame.setVisible(true);
		frame.pack();
	}
	
	public static void main (String[] args){
		EjemploFocusListener eal = new EjemploFocusListener();
		eal.montarVentana();
	}
}
